package com.qubuyer.business.good.adapter;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.qubuyer.R;
import com.qubuyer.business.good.holder.GoodsParamsVH;
import com.qubuyer.repository.entitys.GoodsAttrEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Author: linwg
 * Time: 2020/11/17 0017
 * Description:
 */
public class GoodsParamsAdapter extends RecyclerView.Adapter<GoodsParamsVH> {

    private ArrayList<GoodsAttrEntity> dataList = new ArrayList<>();

    public void setDataList(List<GoodsAttrEntity> dataList) {
        if (dataList == null) {
            return;
        }
        this.dataList.clear();
        this.dataList.addAll(dataList);
        notifyDataSetChanged();
    }

    public void addDataList(List<GoodsAttrEntity> dataList) {
        if (dataList == null) {
            return;
        }
        this.dataList.addAll(dataList);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public GoodsParamsVH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new GoodsParamsVH(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_goods_attr, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull GoodsParamsVH holder, int position) {
        GoodsAttrEntity entity = dataList.get(holder.getLayoutPosition());
        holder.tvAttrName.setText(entity.getCkey());
        holder.tvAttrValue.setText(entity.getAttrvalue());
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }
}
